package com.tushen.utils;


import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by likun on 2020/8/4.
 */

public class CommonQuery {

    public static Object QueryByName(Object mapper, String func,HashMap map) throws Exception{
        Method method = mapper.getClass().getMethod(func, HashMap.class);
        Object sqlResult =  method.invoke(mapper, map);
        return sqlResult;
    }


    public static HashMap getYunyingIndex(Object dao,HashMap json, String func) {
        System.out.println(json);
        long start=System.currentTimeMillis();
        HashMap<String,Object> resultMap=new HashMap<String, Object>();
        try {
            resultMap.put("data",QueryByName(dao,func,json));
            resultMap.put("code",1);
            resultMap.put("msg","操作成功");
        }catch (Exception e){
            resultMap.put("code",-1);
            e.printStackTrace();
            resultMap.put("msg",e.getMessage());
            ArrayList list=new ArrayList();
            resultMap.put("data",list);

        }
        System.out.println("耗时："+(System.currentTimeMillis()-start)/1000.0+"秒");
        return resultMap;
    }

}